//
//  UIGestureViewController.swift
//  swift-practice
//
//  Created by 余振涛 on 2021/8/23.
//

import UIKit

class UIGestureViewController: UIViewController {

    lazy var aview = {() -> UIView in
        var TempView = UIView.init(frame: CGRect(x: 0, y: 100, width: 100, height: 100));
        TempView.backgroundColor = .yellow
        return TempView
    }
    
    lazy var bview : UIView = UIView.init()
    
    init(withTitle title:String){
        super.init(nibName: nil, bundle: nil)
        self.title = title
        self.view.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        setImage()
    }
    
    func setImage() {
        self.view.addSubview(self.aview())
        self.view.addSubview(self.bview)
//        self.aview().frame = CGRect(x: 0, y: 100, width: 100, height: 100)
//        self.aview().backgroundColor = .yellow
        self.bview.frame = CGRect(x: 0, y: 200, width: 100, height: 100)
        self.bview.backgroundColor = .red
        let gesture = UITapGestureRecognizer.init(target: self, action: #selector(onTap))
        self.aview().addGestureRecognizer(gesture)
        self.bview.addGestureRecognizer(gesture)
    }

    @objc func onTap() {
        self.aview().backgroundColor = UIColor.init(red: CGFloat(arc4random() % 256) / 255, green: CGFloat(arc4random() % 256) / 255, blue: CGFloat(arc4random() % 256) / 255, alpha: 1)
        self.bview.backgroundColor = UIColor.init(red: CGFloat(arc4random() % 256) / 255, green: CGFloat(arc4random() % 256) / 255, blue: CGFloat(arc4random() % 256) / 255, alpha: 1)
    }


}
